package com.zj.ssm.controller;

import com.alipay.api.AlipayApiException;
import com.zj.ssm.bean.AliPayBean;
import com.zj.ssm.service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ali")
public class OrderController {
 
    /**日志对象*/
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);
 
    @Autowired
    private PayService payService;
 
    @RequestMapping("/pay")
    public String alipay(String outTradeNo, String subject, String totalAmount) throws AlipayApiException {
 
        logger.info("商户订单号为{},订单名称为{},付款金额为{}", outTradeNo, subject, totalAmount);
        AliPayBean alipayBean = new AliPayBean();
        alipayBean.setOut_trade_no(outTradeNo);
        alipayBean.setSubject(subject);
        alipayBean.setTotal_amount(totalAmount);
 
 
        return payService.aliPay(alipayBean);
    }
 
    @RequestMapping("/success")
    @ResponseBody
    public String success(){
        return "交易成功！";
    }
 
    @RequestMapping(value = "/index")
    public String payCoin(){
        return "order.html";
    }
}
 